﻿/**
 * 描边显示 勾选RaycastTarget的UI,以做优化使用
 **/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class OptimizeUIRaycast : MonoBehaviour
{
#if UNITY_EDITOR
    static Vector3[] fourCorners = new Vector3[4];

    private void OnDrawGizmos()
    {
        foreach (var item in GameObject.FindObjectsOfType<MaskableGraphic>())
        {
            if (item.raycastTarget)
            {
                RectTransform rect = item.rectTransform;
                rect.GetWorldCorners(fourCorners);
                Gizmos.color = Color.blue;
                for (int i = 0; i < fourCorners.Length; i++)
                {
                    Gizmos.DrawLine(fourCorners[i], fourCorners[(i + 1) % fourCorners.Length] );
                }
            }
        }
    }
#endif
}
